package memento;

public class Client {

    public static void main(String[] args) {
        // 创建一个原发器
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();
        originator.setState("状态 1");
        System.out.println(originator.getState());
        // 保存状态
        Memento memento = originator.saveToMemento();
        caretaker.addMemento(memento);
        // 修改
        System.out.println("修改一下吧");
        originator.setState("状态 2");
        caretaker.addMemento(originator.saveToMemento());
        System.out.println(originator.getState());


        // 恢复
        originator.restoreFromMemento(caretaker.getMemento(0));
        System.out.println(originator.getState());

    }

}
